/*
 * @Author: liuzibin
 * @Date: 2023-07-24 00:34:27
 * @Descroption: 创建购物车订单
 */
const axios = require("axios");

async function createCart({ productId, userToken, storeDetail }) {
  const key = Object.keys(storeDetail.sku)[0];

  const response = await axios.post(
    "https://borderclear.cn/api/user/cart/create",
    {
      is_new: 1, //是否立即购买 固定为1
      product_id: productId, // 商品id
      cart_num: 1, // 购买数量
      product_attr_unique: storeDetail.sku[key].unique, //商品属性
      product_type: 0, //商品类型 0.普通商品 2.预售商品  此处固定为0
      spread_id: "", //推广人id 固定为空
    },
    {
      headers: {
        Accept: "application/json, text/plain, */*",
        Referer: "http://borderclear.cn/admin/merchant/list",
        "X-Token": userToken,
        "User-Agent":
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
        "Content-Type": "application/json;charset=UTF-8",
      },
    }
  );
  console.log(response.data);
  return response.data.data.cart_id;
}

module.exports = createCart;
